/*
 MIT License
 
 Copyright (c) 2021 Steven Le

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in all
 copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
*/

#include<stdio.h>
#include<stdlib.h>
#include<stddef.h>
#include<uchar.h>
#include<locale.h>

int main(void)
{
	// 字符数组，字符数组的类型是 char[N]，其中N代表字符串在执行狭小编码的代码单元，包含空结束符。
	// 数组中每一个char元素都被 UTF-8‘s-char-sequence’中的下一个多字符字节初始化。
	char s1[] = "a猫\U0001F34C";	  // or "a\u732B\U0001F34C"
	// UTF-8 字符串，字符串的类型是 char[N]，其中N代表字符UTF-8 编码猿并且包含了空的结束符。
	// 数组中每一个char元素都被 UTF-8‘s-char-sequence’中的下一个多字符字节初始化。
	char s2[] = u8"a猫\U0001F34C";
	// 16位宽字符串，字符串的类型是 char16_t[N], 其中N是字符串的大小，在编码单元为实施-定义16位编码（典型为UTF-16)，包括空结束符。
	// 每一个char16_t 数组中元素都以类似于执行mbrtoc16 为实施-定义时区的方式进行初始化。
	char16_t s3[] = u"a猫\U0001F34C";	
	// 32位宽字符串，字符串的类型是 char32_t[N], 其中N是字符串的大小，在编码单元为实施-定义32位编码（典型为UTF-32)，包括空结束符。
	// 每一个char32_t 数组中元素都以类似于执行mbrtoc32 为实施-定义时区的方式进行初始化。
	char32_t s4[] = U"a猫\U0001F34C";	
	// 宽字符串，字符串的类型是 wchar_t[N], 其中N是字符串的大小，在编码单元为实施-定义宽编码，包括空结束符。
	// 每一个char32_t 数组中元素都以类似于执行mbstowcs 为实施-定义时区的方式进行初始化。
	wchar_t s5[] = L"a猫\U0001F34C";	

	// 设置文件的utf编码
	setlocale(LC_ALL, "en_US.utf8");
	// 打印 s1
	printf("  \"%s\" is a char[%zu] holding 	{ ", s1, sizeof s1/ sizeof *s1);	
	for (size_t n = 0; n < sizeof s1 / sizeof *s1; ++n)
		printf("0x%02X ", +(unsigned char)s1[n]);
	puts("}");
	// 打印s2
	printf("u8\"%s\" is a char[%zu] holding 	{ ", s2, sizeof s2/ sizeof *s2);	
	for (size_t n = 0; n < sizeof s2 / sizeof *s2; ++n)
		printf("0x%02X ", +(unsigned char)s2[n]);
	puts("}");
	// 打印s3
	printf(" u\"a猫\U0001F34C\" is a char16_t[%zu] holding 	{", sizeof s3 / sizeof *s3);	
	for (size_t n = 0; n < sizeof s3 / sizeof *s3; ++n)
		printf("0x%04X ", s3[n]);
	puts("}");
	// 打印s4
	printf(" U\"a猫\U0001F34C\" is a char32_t[%zu] holding 	{", sizeof s4 / sizeof *s4);
	for (size_t n = 0; n < sizeof s4 / sizeof *s4; ++n)
		printf("0x%08X ", s4[n]);
	puts("}");

	// 打印s5
	printf(" L\"a猫\U0001F34C\"  is a wchar_t[%zu] holding  { ", sizeof s5 / sizeof *s5);	
	for (size_t n = 0; n < sizeof s5 / sizeof *s5; ++n)
		printf("0x%08X ", (unsigned)s5[n]);
	puts("}");

	return 0;
}
